package com.atom.plugin.core.test

import com.atom.plugin.core.CorePlugin
import com.atom.plugin.core.Log
import jdk.internal.org.objectweb.asm.ClassReader
import org.apache.commons.io.IOUtils
import java.io.InputStream

class PrintCorePlugin : CorePlugin<PrintExtension>() {

    override fun getExtensionName(): String {
        return this.javaClass.simpleName
    }

    override fun getExtensionClass(): Class<PrintExtension> {
        return PrintExtension::class.java
    }

    override fun collectClassStream(inputStream: InputStream, isFromJar: Boolean) {
        val classReader = ClassReader(inputStream)
        Log.e("""
            [collectClassStream]
            isFromJar:${isFromJar}
            name:${classReader.className}
        """.trimIndent())
    }

    override fun transformClassStream(inputStream: InputStream): ByteArray {
        val array = IOUtils.toByteArray(inputStream)
        val classReader = ClassReader(array)
        //com/atom/bytecode/MainActivity
        Log.e("""
            [transformClassStream]
            ${classReader.className}
        """.trimIndent())
        return array
    }
}